#include <stdio.h>
#include <stdlib.h> 
#include <unistd.h>

#define N 10

typedef void (*callback_t)();

void Worker()
{
    int cnt = 10;
    while(cnt)
    {
        printf("I am child process, pid: %d, ppid: %d, cnt: %d\n", getpid(), getppid(), cnt);
        sleep(1);
        cnt--;
    }
}

void createSubProcess(int n, callback_t cb)
{
    for(int i = 0; i < n; i++)
    {
        sleep(1);
        int id = fork();
        if(0 == id)
        {
            // child
            printf("create child process success: %d\n", i);
            Worker();
            exit(0);
        }
    }
}

int main()
{
    createSubProcess(N, Worker);
    // 子进程先退出，僵尸进程 
    // 只有父进程走到这里
    sleep(100);

    return 0;
}
